package br.trainee.web.controller;


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import br.trainee.web.util.UtilFuncoes;
import br.trainee.web.vo.ClinicaVO;

@WebServlet("/imagem")
public class ImagemController extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			
		
		
		
		PrintWriter p = response.getWriter();
		p.print("<html>");
		RequestDispatcher req = request.getRequestDispatcher("/fieldValidation.jsp");
		req.forward(request, response);
		
		
		HttpSession sessao = request.getSession();
		
		ClinicaVO clinica = (ClinicaVO) sessao.getAttribute(UtilFuncoes.CLINICA_ALTERAR);
		
		byte[] imagem = clinica.getFotoClinica();
		
		if(imagem != null){
		
			response.setContentType("image/jpg");
			response.setContentLength(imagem.length);
			
			ServletOutputStream saida = response.getOutputStream();
			saida.write(imagem);
		}
		

	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
	}
}
